package org.example.server.goods.mapstruct.snapshot;

import cn.hutool.core.date.DateUtil;
import org.example.api.goods.goods.enums.GoodsStatusEnum;
import org.example.api.goods.goods.enums.GoodsTagTypeEnum;
import org.example.api.goods.goods.enums.GoodsTypeEnum;
import org.example.api.goods.goods.enums.SalesTypeEnum;
import org.mapstruct.Named;

import java.util.Date;

public interface BaseConverter {
  @Named("stringToDate")
  default Date stringToDate(String date) {
    return date != null ? DateUtil.parse(date, "yyyy-MM-dd HH:mm:ss") : null;
  }

  @Named("stringToGoodsStatusEnum")
  default GoodsStatusEnum goodsStatusEnum(String status) {
    return status != null ? GoodsStatusEnum.getByCode(status) : null;
  }

  @Named("stringToGoodsTypeEnum")
  default GoodsTypeEnum goodsTypeEnum(String type) {
    return type != null ? GoodsTypeEnum.getByCode(type) : null;
  }

  @Named("stringToSalesTypeEnum")
  default SalesTypeEnum salesTypeEnum(String type) {
    return type != null ? SalesTypeEnum.getByCode(type) : null;
  }

  @Named("stringToGoodsTagTypeEnum")
  default GoodsTagTypeEnum goodsTagTypeEnum(String type) {
    return type != null ? GoodsTagTypeEnum.getByCode(type) : null;
  }

}
